package com.lmonkey.servlet.home;

import com.lmonkey.servic.CARTDao;
import com.lmonkey.servic.CATAGORYDao;
import com.lmonkey.shop.CATEGORY;
import com.lmonkey.shop.USER;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/shangc/indexselect")
public class IndexSelect extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        ArrayList<CATEGORY> flist = CATAGORYDao.selectcat("father");
        request.setAttribute("flist",flist);

        //判断用户是否登入
        HttpSession session = request.getSession();
        String isLogin = (String)session.getAttribute("isLogin");
        USER user = (USER)session.getAttribute("name");
        if (user != null && isLogin.equals("1")){
            String uid = user.getuser_id();
            int count = CARTDao.selectByid(uid);
            request.setAttribute("num",count);
        }

        ArrayList<CATEGORY> clist = CATAGORYDao.selectcat("child");
        request.setAttribute("clist",clist);


        request.getRequestDispatcher("index.jsp").forward(request,response);

    }
}
